import jdk.jshell.Snippet;
import jdk.net.SocketFlow;

import java.util.Scanner;

public class Class1 {
    static String [][] users={
            {"usera","111111","1000"},
            {"userb","222222","2000"},
            {"userc","333222","33000"},
            {"userd","444222","4000"},
            {"usere","555222","5000"}
    };
    static  int using=0;
    static  int zhuan=0;
    static  Scanner sc =new  Scanner(System.in);
    public static void main(String[] args){
        process();

    }
    public static void process(){
        System.out.println("welcome!");
        while(true){
        login();
        menu();
        }
    }
    public static void login( ) {
        for (int j = 0; j < 3; j++) {
            System.out.println("请输入账号");
            String account = sc.next();
            System.out.println("请输入密码");
            String pwd = sc.next();
            for (int i = 0; i < users.length; i++) {
                if (users[i][0].equals(account) && users[i][1].equals(pwd)) {
                    System.out.println("登陆成功");
                    using=i;
                    return ;
                }
            }
            System.out.println("登陆失败还剩"+(2-j)+"次");
        }
        System.out.println("次数已经被用完");
        System.exit(0);     //弹出程序
    }
    public static void menu(){
        while(true) {
            System.out.println("请选择 1查询,2存款,3取款,4转账,5切换账号,6退出");
            int imput = sc.nextInt();
            if (imput == 1) {
                search();
            }
            if (imput == 2) {
                save();
            }
            if (imput == 3) {
                get();
            }
            if (imput == 4) {
                transfer();
            }
            if (imput == 5) {

                login();
            }
            if (imput == 6) {
                System.exit(0);

            }
            else {
                System.out.println("输入有误");
                }

        }
    }
    public static void save(){
        System.out.println("请输入存额");
        double money=sc.nextDouble();
        users[using][2]=Double.parseDouble(users[using][2])+money+"";
        System.out.println("存款成功！");
    }
    public static void get(){
        System.out.println("请输入取款额");
        double money=sc.nextDouble();
        if(Double.parseDouble(users[using][2])>=money){
            users[using][2]=Double.parseDouble(users[using][2])-money+"";
        }
        else{
            System.out.println("输入额度有误，请重新输入");
        }
    }
    public static void search(){
        int c=using;
        System.out.println(users[c][2]);
    }
    public static void transfer() {
        System.out.println("请输入转移账号");
        String  acoun = sc.next();
        for (int i = 1; i < users.length; i++){
            if(users[i][0].equals(acoun)){
                zhuan=i;
            System.out.println("请输入额");
            double money = sc.nextDouble();
             if (Double.parseDouble(users[using][2]) >= money) {
                 users[using][2] = Double.parseDouble(users[using][2]) - money + "";
                 users[zhuan][2] = Double.parseDouble(users[zhuan][2]) + money + "";
                }
            else {
                System.out.println("输入额度有误，请重新输入");

                }
            return;
            }
            else{
                System.out.println("账户输入错误，请重输入");
                return;
            }
        }
    }
}
